#!/bin/bash

# 设置基础 URL 和认证 token
BASE_URL="http://127.0.0.1:8000/api/v1"
TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzM1Mzg1NjU4LCJpYXQiOjE3MzUyOTkyNTgsImp0aSI6IjRlMTg5NTUyMGM0ZjRlZDM5MTdmYWI4MTlmZDU0MDAyIiwidXNlcl9pZCI6MX0.EbUC0hOlloSMFmJI_yK40b0guHBEga6So_ACvhWNGJY"

echo "测试图谱 API..."

# 1. 创建结构化图谱
echo "1. 创建结构化图谱"
curl -X POST "${BASE_URL}/graph/" \
    -H "Authorization: Bearer ${TOKEN}" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "测试数据库图谱",
        "graph_type": "structured",
        "data_source": {
            "db_type": "mysql",
            "db_name": "test_db",
            "username": "root",
            "password": "123456",
            "host": "localhost",
            "port": 3306
        }
    }'
echo -e "\n"

# 2. 创建非结构化图谱
echo "2. 创建非结构化图谱"
curl -X POST "${BASE_URL}/graph/" \
    -H "Authorization: Bearer ${TOKEN}" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "测试文档图谱",
        "graph_type": "unstructured"
    }'
echo -e "\n"

# 3. 获取图谱列表
echo "3. 获取图谱列表"
curl -X GET "${BASE_URL}/graph/" \
    -H "Authorization: Bearer ${TOKEN}"
echo -e "\n"

# 4. 测试数据库连接
echo "4. 测试数据库连接"
curl -X POST "${BASE_URL}/graph/1/test_connection/" \
    -H "Authorization: Bearer ${TOKEN}"
echo -e "\n"

# 5. 上传文件到非结构化图谱
echo "5. 上传文件"
curl -X POST "${BASE_URL}/graph/2/upload_file/" \
    -H "Authorization: Bearer ${TOKEN}" \
    -F "file=@./test.pdf"
echo -e "\n" 